using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace DocumentManagement
{
  /// <summary>
  /// Tnotify Data Object Class
  /// </summary>
  public partial class DOTnotify
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Tnotify UniqueID
		/// </summary>
		public const string RowUniqueID = "UniqueID";

		/// <summary>
		/// The Table Column for the Tnotify msgtype
		/// </summary>
		public const string Rowmsgtype = "msgtype";

		/// <summary>
		/// The Table Column for the Tnotify empno
		/// </summary>
		public const string Rowempno = "empno";

		/// <summary>
		/// The Table Column for the Tnotify tfileno
		/// </summary>
		public const string Rowtfileno = "tfileno";

		/// <summary>
		/// The Table Column for the Tnotify ILPno
		/// </summary>
		public const string RowILPno = "ILPno";

		/// <summary>
		/// The Table Column for the Tnotify msgtxt
		/// </summary>
		public const string Rowmsgtxt = "msgtxt";

		/// <summary>
		/// The Table Column for the Tnotify fstatus
		/// </summary>
		public const string Rowfstatus = "fstatus";

		/// <summary>
		/// The Table Column for the Tnotify tdatetime
		/// </summary>
		public const string Rowtdatetime = "tdatetime";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spTnotify_Create";
private const string m_StoredProcedureConstDelete = "spTnotify_Delete";
private const string m_StoredProcedureConstRetrieve = "spTnotify_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spTnotify_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spTnotify_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private int m_UniqueID;
		private string m_msgtype;
		private string m_empno;
		private string m_tfileno;
		private string m_ILPno;
		private string m_msgtxt;
		private string m_fstatus;
		private DateTime m_tdatetime;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOTnotify> m_Tnotifys = new List<DOTnotify>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOTnotify() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// UniqueID
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify UniqueID
		/// </remarks>
		public int UniqueID
		{
			get { return (this.m_UniqueID); }
			set { this.m_UniqueID = value; }
		}

		/// <summary>
		/// msgtype
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify msgtype
		/// </remarks>
		public string msgtype
		{
			get { return (this.m_msgtype); }
			set { this.m_msgtype = value; }
		}

		/// <summary>
		/// empno
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify empno
		/// </remarks>
		public string empno
		{
			get { return (this.m_empno); }
			set { this.m_empno = value; }
		}

		/// <summary>
		/// tfileno
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify tfileno
		/// </remarks>
		public string tfileno
		{
			get { return (this.m_tfileno); }
			set { this.m_tfileno = value; }
		}

		/// <summary>
		/// ILPno
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify ILPno
		/// </remarks>
		public string ILPno
		{
			get { return (this.m_ILPno); }
			set { this.m_ILPno = value; }
		}

		/// <summary>
		/// msgtxt
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify msgtxt
		/// </remarks>
		public string msgtxt
		{
			get { return (this.m_msgtxt); }
			set { this.m_msgtxt = value; }
		}

		/// <summary>
		/// fstatus
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify fstatus
		/// </remarks>
		public string fstatus
		{
			get { return (this.m_fstatus); }
			set { this.m_fstatus = value; }
		}

		/// <summary>
		/// tdatetime
		/// </summary>
		/// <remarks>
		/// This property contains the Tnotify tdatetime
		/// </remarks>
		public DateTime tdatetime
		{
			get { return (this.m_tdatetime); }
			set { this.m_tdatetime = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOTnotify> Tnotifys
	{
	  get { return m_Tnotifys; }
	  set { m_Tnotifys = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public bool Retrieve()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowUniqueID + "=" + this.UniqueID);
      return SetClassPropertiesFromDataSet(resultDS);
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowUniqueID].ToString() != "")
			this.UniqueID = int.Parse(dr[RowUniqueID].ToString());

		if (dr[Rowmsgtype].ToString() != "")
			this.msgtype = dr[Rowmsgtype].ToString();

		if (dr[Rowempno].ToString() != "")
			this.empno = dr[Rowempno].ToString();

		if (dr[Rowtfileno].ToString() != "")
			this.tfileno = dr[Rowtfileno].ToString();

		if (dr[RowILPno].ToString() != "")
			this.ILPno = dr[RowILPno].ToString();

		if (dr[Rowmsgtxt].ToString() != "")
			this.msgtxt = dr[Rowmsgtxt].ToString();

		if (dr[Rowfstatus].ToString() != "")
			this.fstatus = dr[Rowfstatus].ToString();

		if (dr[Rowtdatetime].ToString() != "")
			this.tdatetime = DateTime.Parse(dr[Rowtdatetime].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOTnotify Tnotify = new DOTnotify();
			
					if (dr[RowUniqueID].ToString() != "")
			Tnotify.UniqueID = int.Parse(dr[RowUniqueID].ToString());

		if (dr[Rowmsgtype].ToString() != "")
			Tnotify.msgtype = dr[Rowmsgtype].ToString();

		if (dr[Rowempno].ToString() != "")
			Tnotify.empno = dr[Rowempno].ToString();

		if (dr[Rowtfileno].ToString() != "")
			Tnotify.tfileno = dr[Rowtfileno].ToString();

		if (dr[RowILPno].ToString() != "")
			Tnotify.ILPno = dr[RowILPno].ToString();

		if (dr[Rowmsgtxt].ToString() != "")
			Tnotify.msgtxt = dr[Rowmsgtxt].ToString();

		if (dr[Rowfstatus].ToString() != "")
			Tnotify.fstatus = dr[Rowfstatus].ToString();

		if (dr[Rowtdatetime].ToString() != "")
			Tnotify.tdatetime = DateTime.Parse(dr[Rowtdatetime].ToString());

            this.Tnotifys.Add(Tnotify);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
